package j2024.j202407;

import java.util.PriorityQueue;

public class j20240707 {
    //703
    PriorityQueue<Integer> q;
    int kk;
    public void KthLargest(int k, int[] nums) {
        kk = k;
        q = new PriorityQueue<>();
        for (int i:nums) {
            q.offer(i);
            if(q.size()>kk){
                q.poll();
            }
        }
    }

    public int add(int val) {
        q.offer(val);
        if(q.size()>kk){
            q.poll();
        }
        return q.peek();
    }
}
